package org.iteam.xlz.manager.action.base;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.iteam.web.shiro.ShiroUtil;
import org.iteam.web.struts.action.AbstractModuleAction;
import org.iteam.web.struts.action.RestAction;
import org.iteam.xlz.core.entity.membershipcard.MembershipCardType;
import org.iteam.xlz.core.service.membershipcard.CardTypeService;

@SuppressWarnings("unchecked")
@Results({@Result(name="INDEX",type="freemarker",location="/WEB-INF/content/base/cardtype/index.html"),
		  @Result(name="EDIT",type="freemarker",location="/WEB-INF/content/base/cardtype/edit.html"),
		  @Result(name="NODEINDEX",type="freemarker",location="/WEB-INF/content/base/cardtype/nodeindex.html"),
		  @Result(name="NODEEDIT",type="freemarker",location="/WEB-INF/content/base/cardtype/nodeedit.html")})
public class MemberShipCardTypeAction extends AbstractModuleAction<MembershipCardType> implements RestAction{

	/**
	 * 
	 */
	private static final long serialVersionUID = 6897669996630760263L;
	private final String PATH="/base/cardtype";
	private final String NODEPATH="/base/cardnodetype";
	@Override
	public MembershipCardType getModel() {
		if(null==model){
			model=new MembershipCardType();
		}
		return model;
	}

	@Override
	@Action(PATH+"/index")
	public String index() {
		return INDEX;
	}

	@Override
	@Action(PATH+"/query")
	public String query() {
		map.put("total",CardTypeService.getInstance().counts(null));
		map.put("rows",CardTypeService.getInstance().query(null,page,rows));
		return MAP;
	}

	@Override
	@Action(PATH+"/create")
	public String create() {
		model.setCreator(ShiroUtil.currentAccount());
		map.put("state",CardTypeService.getInstance().create(model));
		return MAP;
	}

	@Override
	@Action(PATH+"/update")
	public String update() {
		map.put("state",CardTypeService.getInstance().update(model));
		return MAP;
	}

	@Override
	@Action(PATH+"/{_id}/delete")
	public String delete() {
		map.put("state",CardTypeService.getInstance().delete(_id));
		return MAP;
	}

	@Override
	public String destroy() {
		return null;
	}

	@Override
	@Action(PATH+"/{_id}/edit")
	public String edit() {
		super.object=CardTypeService.getInstance().findOne(_id);
		return EDIT;
	}

	@Override
	@Action(PATH+"/new")
	public String editNew() {
		return EDIT;
	}
	
	@Action(NODEPATH+"/{_parent}/index")
	public String nodeIndex(){
		return "NODEINDEX";
	}
	
	@Action(NODEPATH+"/{_parent}/query")
	public String nodeQuery(){
		map.put("total",CardTypeService.getInstance().counts(_parent));
		map.put("rows",CardTypeService.getInstance().query(_parent,page, rows));
		return MAP;
	}
	
	@Action(NODEPATH+"/{_parent}/new")
	public String nodeNew(){
		super._id=CardTypeService.getInstance().findOne(_parent).getTypename();
		return "NODEEDIT";
	}
	
	@Action(NODEPATH+"/{_parent}/create")
	public String nodeCreate(){
		model.setTypeparent(_parent);
		model.setCreator(ShiroUtil.currentAccount());
		map.put("state",CardTypeService.getInstance().create(model));
		return MAP;
	}
	
	@Action(NODEPATH+"/{_parent}/{_id}/edit")
	public String nodeEdit(){
		super.object=CardTypeService.getInstance().findOne(_id);
		super._id=CardTypeService.getInstance().findOne(_parent).getTypename();
		return "NODEEDIT";
	}
	
	@Action(NODEPATH+"/{_parent}/update")
	public String nodeUpdate(){
		map.put("state",CardTypeService.getInstance().update(model));
		return MAP;
	}

	@Action(NODEPATH+"/{_parent}/{_id}/delete")
	public String nodeDelete() {
		map.put("state",CardTypeService.getInstance().delete(_id));
		return MAP;
	}

	@Override
	public String show() {
		return null;
	}
}
